($ => {
    $.fn.extend({
        zidonglunbo() {
            let imgIndex = 0;
            let pointIndex = 0;
            let timer = null;
            let istrue = true;
            this.find('div:first').clone(true).appendTo(this);
            for (let i = 1; i < this.find('.bannerd').length; i++) {
                this.append($(`<div>${i}</div>`)).children().eq(0).addClass('current');
            }
            
            autoPlay = () => {
                imgIndex++;
                if (imgIndex > 3) {
                    imgIndex = 1;
                    this.css('left', 0);
                }
                istrue = false;
                this.stop().animate({
                    left: imgIndex * -1160
                }, 2000,function(fn){
                    istrue=true;
                })
                pointIndex++;
                if (pointIndex > 2) {
                    pointIndex = 0;
                }
                $('.square>span').eq(pointIndex).addClass('current').siblings().removeClass('current');
            }
            timer = setInterval(autoPlay, 3000);
            this.parents(".h3-banner").on('mouseenter', function () {
                clearInterval(timer);
            }).on('mouseleave', function () {
                timer = setInterval(autoPlay, 3000);
            })
            this.parents('.h3-banner').on('click', '.square>span', function () {
               
                console.log(111);
                imgIndex = pointIndex = $(this).index() - 1;//三合一
                autoPlay();
            })
            //右边
            this.parents('.h3-banner').on("click",'.cbtn.b-r',function(){
                if(!istrue){
                    return 
                }
                autoPlay();
            })
            //左边
            this.parents('.h3-banner').on("click",'.cbtn.b-l',function(){
                if(!istrue){
                    return 
                }
                if(imgIndex<=0){
                    pointIndex=2;
                    imgIndex=3;
                    $(".lunbo").css('left', -2320);
                }else{
                    imgIndex-=2;
                autoPlay()
                }
            }) 
        }
    })
})(jQuery)

$(function () {
    $('.lunbo').zidonglunbo();
})
